package com.cyz.user.userService.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.common.bean.ShopType;
import com.cyz.common.enums.MyEnums;
import com.cyz.common.mapper.ShopTypeMapper;
import com.cyz.user.userService.ShopService;
import com.cyz.user.userService.ShopTypeService;
import com.cyz.common.utils.BeanCopyUtil;
import com.cyz.common.utils.R;
import com.cyz.user.vo.ShopTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 34928
* @description 针对表【shop_type】的数据库操作Service实现
* @createDate 2023-02-20 11:05:53
*/
@Service
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType>
    implements ShopTypeService {

    @Autowired
    private ShopService shopService;

    @Override
    public R queryShopTypesAndShops() {
        //查询所有付费课程分类
        List<ShopType> list = list();
        //vo处理
        List<ShopTypeVo> shopTypeVos = BeanCopyUtil.copyBeanList(list, ShopTypeVo.class);
        //查询包含的课程
        shopTypeVos
                .forEach(item -> item.setShops(shopService.getByType(item.getName())));
        //错误判断
        if(shopTypeVos.isEmpty()){
            return R.error(MyEnums.QUERY_FAIL);
        }
        return R.success(shopTypeVos);
    }

    @Override
    public R queryShopTypes() {
        //查询数据
        List<ShopType> list = list();
        //vo转化
        List<ShopTypeVo> shopTypeVos = BeanCopyUtil.copyBeanList(list, ShopTypeVo.class);
        //错误判断
        if(shopTypeVos.isEmpty()){
            return R.error(MyEnums.QUERY_FAIL);
        }
        return R.success(shopTypeVos);
    }
}




